package org.rcy.framework.mq.timer;


/**
 * @author 吴康桥
 * @Description
 * @date 2022/11/23 15:18
 */

public interface Timer {

    /**
     * Add a new task to this executor. It will be executed after the task's delay
     * (beginning from the time of submission)
     * @param task the task to add
     */
    // 将给定的定时任务插入到时间轮上，等待后续延迟执行
    void add(TimerTask task);

    /**
     * Advance the internal clock, executing any tasks whose expiration has been
     * reached within the duration of the passed timeout.
     * @param timeoutMs
     * @return whether or not any tasks were executed
     */
    // 向前推进时钟，执行已达过期时间的延迟任务
    boolean advanceClock(Long timeoutMs) throws Exception;

    /**
     * Get the number of tasks pending execution
     * @return the number of tasks
     */
    // 获取时间轮上总的定时任务数
    int getSize();

    /**
     * Shutdown the timer service, leaving pending tasks unexecuted
     */
    // 关闭定时器
    void shutdown();
}
